package com.ez.supervise.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ez.supervise.core.Page;
import com.ez.supervise.dao.UserDao;
import com.ez.supervise.dao.base.BaseDaoImpl;
import com.ez.supervise.model.sys.User;

public class UserDaoImpl extends BaseDaoImpl implements UserDao {

    public void insert(Object user) {
	sqlMapClientTemplate.insert("sys.insertUser", user);
    }

    public Object get(Long id) {
	return (User) sqlMapClientTemplate.queryForObject("sys.getUserById", id);
    }

    public void update(Object user) {
	sqlMapClientTemplate.update("sys.updateUser", user);
    }

    public void delete(Long id) {
	sqlMapClientTemplate.update("sys.deleteUser", id);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.dao.UserDao#findByCount(com.ez.supervise.core.Page)
     */
    public int findByCount(Page page) {
	return (Integer) getSqlMapClientTemplate().queryForObject("sys.findUserByCount", page.getConditions());
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.dao.UserDao#findByPage(com.ez.supervise.core.Page)
     */
    public List findByPage(Page page) {
	return getSqlMapClientTemplate().queryForList("sys.findUserByPage", page.getConditions());
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.dao.UserDao#findAllUser()
     */
    public List findAllUser() {
	return getSqlMapClientTemplate().queryForList("sys.findAllUser");
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.dao.UserDao#login(java.lang.String,
     * java.lang.String)
     */
    public User login(String userName, String password) {
	Map map = new HashMap();
	map.put("userName", userName);
	map.put("password", password);
//	List result = getSqlMapClientTemplate().queryForList("sys.login", map);
//	if(result != null && result.size() > 0) {
//	    return (User) result.get(0);
//	}
	return (User) getSqlMapClientTemplate().queryForObject("sys.login", map);
    }

    public List findByOrg(Long orgId) {
	return getSqlMapClientTemplate().queryForList("sys.findByOrg", orgId);
    }

    public void editPassword(User user) {
	sqlMapClientTemplate.update("sys.editPassword", user);
    }

}
